package com.sportschain.app.core.utils;

import android.app.Application;
import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.view.Gravity;
import android.widget.Toast;

/**
 * Created by LYZ on 2018/4/22 0022.
 */
public class ToastUtils {

    private static Application application;

    public static void init(Application app) {
        application = app;
    }

    public static void showShort(String text) {
        showToast(text, Toast.LENGTH_SHORT);
    }

    public static void showShortCenter(String text) {
        showToast(text, Toast.LENGTH_SHORT, Gravity.CENTER);
    }

    public static void showLong(String text) {
        showToast(text, Toast.LENGTH_LONG);
    }

    public static void showLongCenter(String text) {
        showToast(text, Toast.LENGTH_LONG, Gravity.CENTER);
    }

    public static void showToast(String text, int duration, int gravity) {
        Toast toast = new Toast(application);
        toast.setGravity(gravity, 0, 0);
        toast.setDuration(duration);
        AppCompatTextView textView = new AppCompatTextView(application);
        textView.setText(text);
        toast.setView(textView);
        toast.show();
    }

    public static void showToast(String text, int duration) {
        Toast toast = new Toast(application);
        toast.setDuration(duration);
        AppCompatTextView textView = new AppCompatTextView(application);
        textView.setText(text);
        textView.setTextColor(Color.WHITE);
        toast.setView(textView);
        toast.show();
    }
}
